﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="frmComprobanteRetencion.aspx.cs" Inherits="WebProveedores.reportes.frmComprobanteRetencion" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
    <%--<head id="Head1" runat="server">--%>
    <title>Comprobante Retención</title>
    <%--<script type="text/javascript">
        function PrintReport() {
            var viewerReference = $find("ReportViewer1").exportReport(<Format>);

            var stillonLoadState = viewerReference.get_isLoading();

            if (!stillonLoadState) {
                var reportArea = viewerReference.get_reportAreaContentType();
                if (reportArea == Microsoft.Reporting.WebFormsClient.ReportAreaContent.ReportPage) {
                    $find("ReportViewer1").invokePrintDialog();
                }
            }
        }
     </script>--%>
     <%--<script type="text/javascript">

         function setInputEnableState(reportViewer) {

             // It is ok to export if the viewer is not loading and is displaying a report.
             var disableInputs = reportViewer.get_isLoading() ||
                                reportViewer.get_reportAreaContentType() !== Microsoft.Reporting.WebFormsClient.ReportAreaContent.ReportPage;

             $get("ExportFormats").disabled = disableInputs;
             $get("ExportButton").disabled = disableInputs;
         }

         function onReportViewerLoadingChanged(sender, e) {

             var propertyName = e.get_propertyName();

             if (propertyName === "isLoading" || propertyName === "reportAreaContentType") {
                 setInputEnableState(sender);
             }
         }

         function onExportButtonClicked() {

             var exportFormat = $get("ExportFormats").value;

             var reportViewer = $find("rpvr1");
             reportViewer.exportReport(exportFormat);

             var reportViewer2 = $find("ReportViewer2");
             reportViewer2.exportReport(exportFormat);

             var reportViewer3 = $find("ReportViewer3");
             reportViewer3.exportReport(exportFormat);
         }

         var hookedPropertyChangedEvent = false;

         function pageLoad() {

             if (!hookedPropertyChangedEvent) {

                 var reportViewer = $find("rpvr1");
                 reportViewer.add_propertyChanged(onReportViewerLoadingChanged);

                 // Make sure the input controls are in the correct state initially
                 setInputEnableState(reportViewer);

                 // pageLoad is called after each asynchronous postback.  Only
                 // hook the property changed event once.
                 hookedPropertyChangedEvent = true;
             }
         }
    
    </script>--%>

     <style type="text/css">
         .content-report
        {
	        width:auto;	
	        border:1px solid #DBDBDB;	
	        height:500px;
	        margin:0; 
	        padding:0; 
	        vertical-align:top;
	        background-color:#fff;		
        }

        .cnt-print-ticket
        {
	        height:30px;
	        width:100%;
	        background-color:#5D7B9D;	
	        line-height:30px;	
        }

        .cnt-print-ticket a
        {
	        color:#fff;	
	        text-align:right;
	        float:right;
	        margin-right:15px;
	        font-weight:bold;
	        font-size:small;
        }
        .cnt-print-ticket a:hover
        {	
	        text-decoration:underline;
        }
     
     </style>

    <%--<script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        function printdiv(printpage) {
            var headstr = "<html><head><title></title></head><body>";
            var footstr = "</body></html>";
            var newstr = document.getElementById(printpage).innerHTML;
            var oldstr = document.getElementById("body1").innerHTML;
            document.getElementById("body1").innerHTML = headstr + newstr + footstr;
            window.print();
            document.getElementById("body1").innerHTML = oldstr;
            return false;
        }
    </script>--%>
<%--</head>--%>
<body style="top:0; left:0; margin:0">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Release">
        </asp:ScriptManager>
        <div id="body1" class="content-report">
            <div class="cnt-print-ticket">
                <input id="printreport" type="button" value="imprimir" />
            </div>
            <%--<div style="visibility:hidden;">
                <a href="JavaScript:PrintReport()">Imprimir</a>            
                <asp:Button ID="Button1" runat="server" Text="Imprimir" onclick="Button1_Click" 
                    BackColor="#5D7B9D" BorderStyle="None" ForeColor="White" /> 
                    <asp:DropDownList ID="ExportFormats" runat="server" Enabled="False" />
                <asp:Button ID="ExportButton" runat="server" disabled="disabled" Text="Export Report" OnClientClick="onExportButtonClicked();return false;" />
            </div>--%>
            
            <%--<div id="div_print">--%>
            <rsweb:ReportViewer ID="ReportViewer1" runat="server" ShowToolBar="False" Font-Names="Verdana" 
                    Font-Size="8pt" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" 
                    ClientIDMode="Static" Height="500" Width="800px" PageCountMode="Actual" 
                    ShowPageNavigationControls="False" ShowPrintButton="False" 
                    ShowRefreshButton="False" ShowZoomControl="False">
                    <LocalReport ReportPath="reportes\rptComprobanteRetencion.rdlc">
                        <DataSources>
                            <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="dsRetencion" />
                        </DataSources>
                    </LocalReport>
            </rsweb:ReportViewer>
            <%--<div style="display:none;">
            <rsweb:ReportViewer ID="ReportViewer2" runat="server"  ShowToolBar="False" Font-Names="Verdana" 
                    Font-Size="8pt" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" 
                    ClientIDMode="Static" Height="500" Width="500px" PageCountMode="Actual" 
                    ShowPageNavigationControls="False" ShowPrintButton="False" 
                    ShowRefreshButton="False" ShowZoomControl="False">
                    <LocalReport ReportPath="reportes\rptComprobanteRetencionSunat.rdlc">
                        <DataSources>
                            <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="dsRetencion" />
                        </DataSources>
                    </LocalReport>
            </rsweb:ReportViewer>

            <rsweb:ReportViewer ID="ReportViewer3" runat="server" ShowToolBar="False" Font-Names="Verdana" 
                    Font-Size="8pt" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" 
                    ClientIDMode="Static" Height="500" Width="500px" PageCountMode="Actual" 
                    ShowPageNavigationControls="False" ShowPrintButton="False" 
                    ShowRefreshButton="False" ShowZoomControl="False">
                    <LocalReport ReportPath="reportes\rptComprobanteRetencionProveedor.rdlc">
                        <DataSources>
                            <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="dsRetencion" />
                        </DataSources>
                    </LocalReport>
            </rsweb:ReportViewer>
            </div--%>>
            <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
                SelectMethod="selecccionRetenciones" TypeName="Negocio.NePagos">
                <SelectParameters>
                    <asp:SessionParameter Name="sociedad" SessionField="sociedad" Type="String" />
                    <asp:SessionParameter Name="annio" SessionField="annio" Type="String" />
                    <asp:SessionParameter Name="numero_documento" SessionField="numero_documento" Type="String" />
                    <asp:SessionParameter Name="numero_certificado_retencion" 
                        SessionField="numero_certificado_retencion" Type="String" DefaultValue="" />
                    <asp:SessionParameter Name="posicion" SessionField="posicion" Type="Int16" />    
                </SelectParameters>
            </asp:ObjectDataSource>
            
        </div>

        <script type="text/javascript">
            //------------------------------------------------------------------
            // Cross-browser Multi-page Printing with ASP.NET ReportViewer
            // by Chtiwi Malek.
            // http://www.codicode.com
            //------------------------------------------------------------------

            // Linking the print function to the print button
            $('#printreport').click(function () {
                printReport('ReportViewer1');
            });

            // Print function (require the reportviewer client ID)
            function printReport(report_ID) {
                var rv1 = $('#' + report_ID);
                var iDoc = rv1.parents('html');

                // Reading the report styles
                var styles = iDoc.find("head style[id$='ReportControl_styles']").html();
                if ((styles == undefined) || (styles == '')) {
                    iDoc.find('head script').each(function () {
                        var cnt = $(this).html();
                        var p1 = cnt.indexOf('ReportStyles":"');
                        if (p1 > 0) {
                            p1 += 15;
                            var p2 = cnt.indexOf('"', p1);
                            styles = cnt.substr(p1, p2 - p1);
                        }
                    });
                }
                if (styles == '') { alert("Cannot generate styles, Displaying without styles.."); }
                styles = '<style type="text/css">' + styles + "</style>";

                // Reading the report html
                var table = rv1.find("div[id$='_oReportDiv']");
                if (table == undefined) {
                    alert("Report source not found.");
                    return;
                }

                // Generating a copy of the report in a new window
                var docType = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/loose.dtd">';
                var docCnt = styles + table.parent().html();
                var docHead = '<head><title></title><style>body{margin:5;padding:0;}</style></head>';
                var winAttr = "location=yes,statusbar=no,directories=no,menubar=no,titlebar=no,toolbar=no,dependent=no,width=720,height=600,resizable=yes,screenX=200,screenY=200,personalbar=no,scrollbars=yes"; ;
                var newWin = window.open("", "_blank", winAttr);
                writeDoc = newWin.document;
                writeDoc.open();
                writeDoc.write(docType + '<html>' + docHead + '<body onload="window.print();">' + docCnt + '</body></html>');
                writeDoc.close();

                // The print event will fire as soon as the window loads
                newWin.focus();
                // uncomment to autoclose the preview window when printing is confirmed or canceled.
                // newWin.close();
            };

        </script>
    </form>
</body>
</html>
